<?php
if (!defined('BASEPATH'))
	exit('No direct script access allowed');

class membership extends MX_Controller {

	public function __construct() {
		parent::__construct();
		$this->load->model(array('admin_commoncall','admin_settings_model','admin_membership_model'));

		$this->admin_commoncall->check_admin_login();
		$this->template->set_theme('admin');
		$this->template->set_layout('default');
		//$this->template->set_partial('side_menu','layouts/side_menu');
		//$this->template->set_partial('nav_bar','layouts/nav_bar');

	}

	function add()
	{

		//print_r($data['membership']); die();
		$this->template->title('Welcome', 'Ypage.com')
		->set_partial('nav_bar','layouts/nav_bar')
		->set_partial('side_menu','layouts/side_menu')
		->set_partial('footer','footer/footer')
		->build('membership/add');
	}

	function edit($id=NULL)
	{

		$id = $id;
		$data['membership']['info'] = $this->admin_membership_model->getPK($id);

		//print_r($data['membership']); die();
		$this->template->title('Welcome', 'Ypage.com')
		->set_partial('nav_bar','layouts/nav_bar')
		->set_partial('side_menu','layouts/side_menu')
		->set_partial('footer','footer/footer')
		->build('membership/membership',$data);
	}

	function save(){

		
		

		$id = $this->input->post('mem_id');

		if ($this->input->post('save_settings')) {
			$this->form_validation->set_rules('mem_name', 'Title', 'required|xss_clean');
			if ($this->form_validation->run()) {
			$mem_data = array(
					'name'	=> $this->input->post('mem_name'),
					'description'	=> $this->input->post('mem_description'),
					'contact_no'	=> $this->input->post('mem_phone'),
					'email'	=> $this->input->post('mem_email'),
					'website'	=> $this->input->post('mem_website'),
					'contact_form'	=> $this->input->post('mem_contact_form'),
					'contact_person'	=> $this->input->post('mem_contact_person'),
					'logo'	=> $this->input->post('mem_logo'),
					'video'	=> $this->input->post('mem_video'),
					'photo'	=> $this->input->post('mem_photo'),
					'satisfaction_tag'	=> $this->input->post('mem_satisfaction_tag'),
					'keyword_limit'	=> $this->input->post('keyword_limit'),
					'photo_limit' => $this->input->post('photo_limit'),
					'price'	=> $this->input->post('price'),
			);

			
				$this->db->where('id', $id);
				$this->db->update('membership', $mem_data);
				$this->edit($id);
			}else{
				$this->session->set_flashdata('message', 'Invalid Input...');
				redirect('secure/membership/edit/' . $id);
			}
		}

		if ($this->input->post('delete_settings')) {
			$this->db->where('id', $id);
			$this->db->delete('membership');
			redirect('secure/membership/add/');
		}

		$this->session->set_flashdata('message', 'Updated Successfully');
		redirect('secure/membership/edit/' . $id);
	}


	function insert() {

		if ($this->input->post('addnew')) {

			$this->form_validation->set_rules('mem_name', 'Title', 'required|xss_clean|is_unique[membership.name]');
			$this->form_validation->set_rules('mem_description', 'Description', 'required|xss_clean');


			$mem_data = array(
					'name' => $this->input->post('mem_name'),
					'description' => $this->input->post('mem_description'),
			);


			if ($this->form_validation->run()) {

				if ($this->config->item('mode') != 'DEMO'){
					$this->db->insert('membership',$mem_data);
					$lastID = $this->db->insert_id();
					$this->session->set_flashdata('message', 'Added Succesfully...');
					redirect('secure/membership/edit/' . $lastID);
				}
			}
			else {
				$this->session->set_flashdata('message', 'Invalid Input...');
				redirect('secure/membership/add');
			}
		}

	}
}